package com.atguigu.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/servlet3")
public class Servlet3 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //行相关 get post uri http/1,1
        System.out.println(req.getMethod()); //获取请求方式
        System.out.println(req.getScheme()); //获取协议
        System.out.println(req.getProtocol()); //获取协议版本
        System.out.println(req.getRequestURI()); //获取请求路径 项目内  统一资源标识符
        System.out.println(req.getRequestURL()); //获取请求路径 项目资源完整的请求路径  统一资源定位符
        System.out.println(req.getLocalPort()); //本应用容器的端口
        System.out.println(req.getRemotePort());    //客户端发请求的端口号
        //头相关 key value
        System.out.println(req.getHeader("user-agent"));
        //获取本次所有请求头的信息
        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            System.out.println(headerName + ":" + req.getHeader(headerName));
        }
    }
}
